package com.chanzany.proxy.staticProxy;


import java.util.HashMap;
import java.util.Map;

public class TrainStation implements SellTickets {
    protected static int[][] map = new int[4][4];

    static {
        map[stations.BEIJING.code][stations.CHENGDU.code] =
                map[stations.CHENGDU.code][stations.BEIJING.code] =  300;
        map[stations.BEIJING.code][stations.SHANGHAI.code] =
                map[stations.SHANGHAI.code][stations.BEIJING.code] =  400;
        map[stations.BEIJING.code][stations.SHENZHEN.code] =
                map[stations.SHENZHEN.code][stations.BEIJING.code] =  350;

        map[stations.CHENGDU.code][stations.SHANGHAI.code] =
                map[stations.SHANGHAI.code][stations.CHENGDU.code] =  500;
        map[stations.CHENGDU.code][stations.SHENZHEN.code] =
                map[stations.SHENZHEN.code][stations.CHENGDU.code] =  350;

        map[stations.SHANGHAI.code][stations.SHENZHEN.code] =
                map[stations.SHENZHEN.code][stations.SHANGHAI.code] =  320;
    }

    public static Map<String,Integer> cityCodeMap = new HashMap<String,Integer>(){{
        put("BEIJING",0);
        put("CHENGDU",1);
        put("SHANGHAI",2);
        put("SHENZHEN",3);
    }};

    @Override
    public int sell(String from, String to) {
        if (!(cityCodeMap.containsKey(from) && cityCodeMap.containsKey(to)))
            throw new UnsupportedOperationException("暂未开通其他城市的车站");
        int price = map[cityCodeMap.get(from)][cityCodeMap.get(to)];
        System.out.println("从"+from+"发往"+to+"的列车，票价为:"+price);
        return price;
    }
}
